<!--
 * @Description: 
 * @Author: mmzhang
 * @Date: 2022-12-19 15:37:20
 * @LastEditTime: 2023-02-15 09:46:39
-->
<template>
  <div class="process-page">
    <div
      class="flex flex-horizontal-between"
      v-if="processInfo.housesRespList.length && isbuildFlag != 'nobuildpage'">
      <p class="tip-text outer-width" :style="{ height: showFlag ? 'auto' : '40px', 'overflow-y': 'hidden' }">
        <Icon type="md-alert" :size="18" color="#FAAD14" style="line-height: 26px; margin-right: 10px" />
        <span class="inner-width">
          您所在的其他{{ processInfo.housesRespList.length }}个案场还有{{
            processInfo.totalCount
          }}个流程需审批，切换案场：
        </span>
        <span
          class="view hand inner-width"
          @click="viewBuildTask(item)"
          v-for="(item, index) in processInfo.housesRespList"
          :key="index">
          {{ item.housesName }}
        </span>
      </p>
      <Button
        v-if="showBtn"
        @click="downUpFun"
        type="primary"
        :icon="showFlag ? 'ios-arrow-up' : 'ios-arrow-down'">
        {{ showFlag ? '收起' : '展开' }}
      </Button>
    </div>

    <dt-grid ref="table" :columns="columns" :onFetch="onFetch" />
  </div>
</template>
<script>
  import dt from '@dt/dt'
  import caseMgr from '@/biz/crimeSceneList'
  import buildMgr from '@/biz/building'
  import { buildPage } from '@/router/buildPage.js'
  import store from '@/store'
  import processColumn from './processColumn'
  import homeMgr from '@/biz/buildingHome/home'
  import workMgr from '@/biz/work/index'
  export default {
    props: ['isOtherProcess'],
    data() {
      return {
        columns: [],
        processInfo: {
          approvalStatisticsDetailRespList: [],
          housesRespList: [],
          totalCount: 0
        },
        isbuildFlag: 'buildpage',
        linkInfo: {
          HOUSES: 'buildingCheckcenterFirst', //线上售楼处审核
          SUBSCRIBER_ATTACH: 'subEnclose', //认购附件补传审核
          CONTRACTOR_ATTACH: 'contractEnclose', //签约附件补传审核
          SUBSCRIPTION_BACK: 'backOrder', //退购单审核
          CONTRACT_BACK: 'refundOrder', //退签单审核
          ARTICLE_INFO: 'articleReview', //置业计划书审核
          BREAK_LOW_PRICE: 'basePrice', //破底价审核
          BONUS: 'caseBillApproval', //奖金单审核
          // 案场外
          channelCompliance: 'channelCompliance', //渠道合规审核
          earlySale: 'advanceSaleReview', //提前开售审核
          breakingFloorPrice: 'companyBasePrice', //破底价审核
          subscriptionAdjustment: 'subApprove', //认购单调整审核
          contractAdjustment: 'contractApprove', //签约单调整审核
          bonusTemplate: 'templateApproval', //奖金模板审核
          rankTemplate: 'levelApproval', //职级点数审核
          bonusSlip: 'billApproval', //奖金单审核
          salesIncentives: 'incentiveApprove', //在销激励审核
          projectAllowance: 'allowanceApprove', //项目津贴审核
          zeroAppeal: 'appealPage', //0分申诉审核
          businessCard: 'cardAudit', //名片审核
          yearEndBonus: 'yearendApproval', //年底奖金审核
          estatePlan: 'legalArticleReview', //置业计划书审核
          deferApprove: 'deferApprove' //奖金单延期申请审批
        },
        otherLinkInfo: {
          // 他人审批 平台
          TGU: 'returnPurchase', // 退购单审核
          TQU: 'returnNote', // 退签单审核
          D_TZ: 'orderAdjustApproveManagement', //订单调整审批管理
          JJ: 'billApprovalManager', //奖金单审批管理
          JJ_MB: 'templateApprovalManager', //奖金单模板审批管理
          ZJ: 'levelApprovalManager', //职级点数审批管理
          ZX: 'incentiveMar', //在销激励审批审批管理
          XM: 'allowanceMar', // 项目津贴审批管理
          ND: 'yearend', // 年底奖金审批管理
          // 他人审批 案场端
          TG: 'backOrder', // 退购单审核
          TQ: 'refundOrder', // 退签单审核
          D_TZ: 'orderAdjustApproveManagement', //订单调整审批管理
          RG_FJ: 'subEnclose', //认购附件补传审核
          QY_FJ: 'contractEnclose', //签约附件补传审核
          PLAN: 'reportApprove', // 置业计划书审批管理
          JJ: 'billApprovalManager', //奖金单审批管理
          JJ_MB: 'templateApprovalManager', //奖金单模板审批管理
          ZJ: 'levelApprovalManager', // 职级点数审批管理
          ZX: 'incentiveMar', //在销激励审批审批管理
          XM: 'allowanceMar' //项目津贴审批管理
        },
        showFlag: false,
        showBtn: true
      }
    },
    mounted() {
      this.columns = processColumn.column(this)
      this.$refs.table.init(this)
      this.$refs.table.fetch()
      window.addEventListener(
        'resize',
        () => {
          this.showUpDownBtn()
        },
        false
      )
    },
    methods: {
      downUpFun() {
        this.showFlag = !this.showFlag
        this.$refs.table.fixHeight()
      },
      searchFun() {
        this.$refs.table.fetch()
      },
      // 自适应是否展示展开收起按钮
      showUpDownBtn() {
        this.$nextTick(function () {
          let list = document.querySelectorAll('.inner-width')
          let outerWidth = document.querySelector('.outer-width')
            ? document.querySelector('.outer-width').offsetWidth
            : 0
          let sumWidth = 28
          for (let i = 0; i < list.length; i++) {
            sumWidth += list[i].offsetWidth
          }
          this.showBtn = sumWidth > outerWidth ? true : false
        })
      },
      onFetch(data) {
        this.isbuildFlag = this.$tool.getStorage('isbuildFlag')
        let params = {}
        let req = ''
        if (this.isOtherProcess) {
          this.processInfo = {
            approvalStatisticsDetailRespList: [],
            housesRespList: [],
            totalCount: 0
          }
          if (this.isbuildFlag == 'buildpage') {
            params = {
              housesId: this.$dt.buildInfo().housesId
            }
            req = homeMgr.getOtherList(params)
          } else {
            req = homeMgr.getOrgOtherList(params)
          }
          return req
            .then((res) => {
              return res
            })
            .catch((err) => {})
        } else {
          if (this.isbuildFlag == 'buildpage') {
            params = {
              housesId: this.$dt.buildInfo().housesId
            }
            req = homeMgr.getStatisticsDetail(params)
          } else {
            req = workMgr.getOrgStatistics(params)
          }
          return req
            .then((res) => {
              this.processInfo = res
              this.showUpDownBtn()
              return res.approvalStatisticsDetailRespList
            })
            .catch((err) => {})
        }
      },
      viewBuildTask(buildItem) {
        let params = {
          housesId: buildItem.housesId
        }
        store.dispatch('setRouterList', [])
        caseMgr.buildinghousesList(params).then((res) => {
          let item = { ...res.list[0] }
          // 更新案场
          buildMgr.updateBuildInfo(item)
          this.$tool.setStorage({ caseBuildingId: JSON.stringify(item.housesId) })
          store.dispatch('setRouterList', buildPage)
          this.$refs.table.fetch()
          this.$emit('onTaskInfo')
        })
      },
      // 跳转
      linkProcessFun(item) {
        // 流程审批跳转统一处理逻辑   只有刷新页面和点击重置时清空传参。其他情况保留待办任务的参数
        if (this.isOtherProcess) {
          if (this.isbuildFlag == 'nobuildpage' && (item.typeCode == 'TG' || item.typeCode == 'TQ')) {
            item.typeCode = item.typeCode + 'U'
          }

          if (this.otherLinkInfo[item.typeCode] == 'backOrder') {
            let params = {
              backDate: ['', ''],
              status: '3'
            }
            dt.memory.set('backOrder_params', params)
          } else if (this.otherLinkInfo[item.typeCode] == 'refundOrder') {
            let params = {
              backDate: ['', ''],
              businessResult: '3'
            }
            dt.memory.set('refundOrder_params', params)
          } else {
            let params = {
              state: 'APPROVAL',
              UContainSelf: true,
              housesId: this.isbuildFlag == 'buildpage' ? this.$dt.buildInfo().housesId : '',
              companyId: this.isbuildFlag == 'buildpage' ? this.$dt.buildInfo().orgId : '',
              housesName: this.isbuildFlag == 'buildpage' ? this.$dt.buildInfo().housesName : ''
            }
            dt.memory.set(this.otherLinkInfo[item.typeCode], params)
          }
          // 他人审批流
          this.$router.push({
            name: this.otherLinkInfo[item.typeCode]
          })
        } else {
          if (this.linkInfo[item.typeCode] == 'backOrder') {
            let params = {
              backDate: ['', ''],
              status: '3'
            }
            dt.memory.set('backOrder_params', params)
          } else if (this.linkInfo[item.typeCode] == 'refundOrder') {
            let params = {
              backDate: ['', ''],
              businessResult: '3'
            }
            dt.memory.set('refundOrder_params', params)
          } else if (this.linkInfo[item.typeCode] == 'deferApprove') {
            let params = {
              state: 'APPROVAL'
            }
            dt.memory.set('deferApprove', params)
          }

          if (this.linkInfo[item.typeCode] == 'channelCompliance') {
            this.$router.push({
              name: this.$dt.unlocking('0206010104') ? 'companyAudit' : 'businessAudit'
            })
          } else {
            this.$router.push({
              name: this.linkInfo[item.typeCode],
              params: {
                status: '0'
              }
            })
          }
        }
      }
    }
  }
</script>
<style lang="scss" scoped>
  .process-page {
    .tip-text {
      margin-right: 10px;
      width: 100%;
      line-height: 40px;
      background-color: rgba(254, 252, 236, 1);
    }

    .view {
      padding-left: 10px;
      color: #2d8cf0;
    }
  }
</style>
